<template>
  <div class="main">
   <van-form>
      <van-field class="input_text" label="证书名称" v-model="form.CertName" />
      <van-field class="input_text" label="证书编号" v-model="form.CertCode" />
      <van-field
        class="input_text"
        readonly
        label="有效期"
        :value="form.NextReviewDate"
        placeholder="点击选择日期"
        @click="handleShow('NextReviewDate')"
      />
      <FileUpload @CallBack="_fileUploadCb" :attachs="form.Attach" :labelName="'证书附件'"/>
  	</van-form>
    	<van-calendar
				color="#1989fa"
				v-model="showCalendar"
				@confirm="onConfirm"
			/>
      <div class="btn_submit">
				<van-button block type="info" @click="submit"> 提交 </van-button>
			</div>
  </div>
</template>

<script>
import FileUpload from "@/components/Attach/FileUpload";
import { getDetail, save} from "@/api/constructSafeUserCert";
import { formatDate, getDate, getTime } from '@/utils/getDate'

import { mapGetters } from "vuex";

export default {
  components: {
    FileUpload,
  },
  data() {
    return {
      showCalendar:false,
      form: {
        CertName: "",
        CertCode: "",
        NextReviewDate: "",
        Attach: "",
        ID:0
      },
      border: false
    };
  },
  created() {
    this.form.ID = this.$route.query.id;
    this.getDetail();
  },
  computed: {

  },
  methods: {
    _fileUploadCb(attachs) {
      this.form.Attach = attachs;
    },
    getDetail() {
      let params = { id: this.form.ID };
      if (this.form.ID > 0) {
        getDetail(params).then((res) => {
          res.data.NextReviewDate = getTime(res.data.NextReviewDate);
          this.form = res.data;
        });
      }
    },
 
    handleShow(name) {
      this.showCalendar = true;
      this.selectKey = name;
    },
	onConfirm(date) {
			const dateTime = formatDate(date)
			this.form[this.selectKey] = getDate(dateTime)
			this.showCalendar = false
		},
    // 附件详情
    _goEnclosure(item) {
      // console.log(item,'sdvfdvdcd')
      this.$router.push({
        path: "/Credential/Enclosure",
        query: { attCode: item.AttCode },
      });
    },
    submit(){
       save(this.form).then((res) => {
         if(res.success)
         {
           this.$toast.success('保存成功！');
          this.$router.push('ConstructSafeCertList');
        }});
    },
  },
};
</script>

<style lang="less">
.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}
.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}

.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    border: 1px solid #e8f1f8;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      /*margin-bottom: 10px;*/
    }
  }
}
</style>
